﻿using AutoMapper;
using MediatR;
using T_Person.APi.Applation.CommandHandlers.EmployeeHandlers;
using T_Person.BaseRep.Interface;
using T_Person.Domain;

namespace T_Person.APi.Applation.Commands.EmployeeCommand
{
    public class EmployeeUpdateCommand : IRequestHandler<EmployeeUpdateHandlers, int>
    {
        private readonly IMapper mapper;
        private readonly IEmployeeRep employeeRep;

        public EmployeeUpdateCommand(IMapper mapper, IEmployeeRep employeeRep)
        {
            this.mapper = mapper;
            this.employeeRep = employeeRep;
        }

        public async Task<int> Handle(EmployeeUpdateHandlers request, CancellationToken cancellationToken)
        {
            var list = mapper.Map<Employee>(request);
            return await employeeRep.Update(list);
        }
    }
}
